package com.alliky.core.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alliky.core.entity.BaseResponse;

import java.util.List;

/**
 * @Description: java类作用描述
 * @Author: wxianing
 * @CreateDate: 2021/3/4 0004 10:39
 * @Version: 1.0
 */
public class JSONUtils {

    public static <T> BaseResponse parseObject(String json) {
        BaseResponse<T> baseResponse = JSONObject.parseObject(json, new TypeReference<BaseResponse<T>>() {
        });
        return baseResponse;
    }

    public static <T> T parseObject(String json, Class<T> clazz) {
        return JSON.parseObject(json, clazz);
    }

    public static <T> List<T> parseArray(String json, Class<T> clazz) {
        return JSON.parseArray(json, clazz);
    }

    public static String toJSON(Object object) {
        return JSON.toJSONString(object);
    }
}
